﻿using System;
using UnityEditor;
using UnityEngine;
using System.IO;

namespace hxweditor
{
	public class AssetBundleEditor:BaseEditorWindow<AssetBundleEditor>
	{

		string buildTargetKey = "AssetBundleEditor_buildTargetKey";
		BuildTarget buildTarget = BuildTarget.StandaloneWindows;

		string assetBundleOptionKey = "AssetBundleEditor_assetBundleOptionKey";
		BuildAssetBundleOptions assetBundleOption = BuildAssetBundleOptions.UncompressedAssetBundle;

		string outputPathKey = "AssetBundleEditor_outputPathKey";
		string outputPath = "请输入输出路径";

		string uiAtlasPathKey = "AssetBundleEditor_uiAtlasPathKey";
		string uiAtlasPath = "请输入uiAtlas根目录";

		string effectPathKey = "AssetBundleEditor_effectPathKey";
		string effectPath = "请输入Effect根目录";

		string actorPathKey = "AssetBundleEditor_ActorPathKey";
		string actorPath = "请输入actor根目录";

        string scenePathKey = "AssetBundleEditor_scenePath";
        string scenePath = "请输入scene根目录";

		AssetBundleEditor()
		{
			this.titleContent = new GUIContent("打包编辑器");
		}

		void OnEnable ()
		{
			buildTarget = (BuildTarget)PlayerPrefs.GetInt (buildTargetKey, (int)BuildTarget.StandaloneWindows);
			assetBundleOption = (BuildAssetBundleOptions)PlayerPrefs.GetInt (assetBundleOptionKey, (int)BuildAssetBundleOptions.UncompressedAssetBundle);
			outputPath = PlayerPrefs.GetString (outputPathKey, "请输入输出路径");
			uiAtlasPath = PlayerPrefs.GetString (uiAtlasPathKey, "请输入uiAtlas根目录");
			effectPath = PlayerPrefs.GetString (effectPathKey, "请输入Effect根目录");
			actorPath = PlayerPrefs.GetString (actorPathKey, "请输入actor根目录");
            scenePath = PlayerPrefs.GetString(scenePathKey, "请输入scene根目录");
		}

		void OnDisable ()
		{
			PlayerPrefs.SetInt (buildTargetKey, (int)buildTarget);
			PlayerPrefs.SetInt (assetBundleOptionKey, (int)assetBundleOption);
			PlayerPrefs.SetString (outputPathKey, outputPath);
			PlayerPrefs.SetString (uiAtlasPathKey, uiAtlasPath);
			PlayerPrefs.SetString (effectPathKey, effectPath);
			PlayerPrefs.SetString (actorPathKey, actorPath);
            PlayerPrefs.SetString(scenePathKey, scenePath);
		}

		void OnGUI ()
		{

			buildTarget = (BuildTarget)ShowPopUp ("平台类型:", buildTarget);

			assetBundleOption = (BuildAssetBundleOptions)ShowPopUp ("编译类型:", assetBundleOption);

			outputPath = ShowInputString ("输出路径:", outputPath);

			ShowSpaceLine (1);

			uiAtlasPath = ShowInputString ("uiAtlas根目录:", uiAtlasPath);
			if (ShowButton ("打包UIAtlas")) {
				AssetBundleTool.CreatAssetBundle (uiAtlasPath, outputPath, buildTarget, assetBundleOption, AssetBundleBuildType.ui);
			}

            ShowSpaceLine(1);

            scenePath = ShowInputString("Scene根目录:",scenePath);
            if (ShowButton("打包场景"))
            {
                AssetBundleTool.CreatAssetBundle(scenePath, outputPath, buildTarget, assetBundleOption, AssetBundleBuildType.scene);
            }

			ShowSpaceLine (1);

			actorPath = ShowInputString ("Actor根目录:", actorPath);
			if (ShowButton ("打包Actor")) {
				AssetBundleTool.CreatAssetBundle (actorPath, outputPath, buildTarget, assetBundleOption, AssetBundleBuildType.actor);
			}

			ShowSpaceLine (1);

			effectPath = ShowInputString ("特效根目录:", effectPath);
			if (ShowButton ("打包特效")) {
				AssetBundleTool.CreatAssetBundle (effectPath, outputPath, buildTarget, assetBundleOption, AssetBundleBuildType.effect);
			}
	
			ShowSpaceLine (2);

			if (ShowButton ("copyToStreamingAssets")) {

			}

		}

	}
}